package com.ruoyi.project.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.project.vo.CompomentInfoListVO;
import com.ruoyi.project.vo.CompomentInfoVO;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.project.domain.CompomentInfo;
import com.ruoyi.project.service.ICompomentInfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 构件维护Controller
 * 
 * @author LiuDongyi
 * @date 2022-08-27
 */
@RestController
@RequestMapping("/project/info")
public class CompomentInfoController extends BaseController
{
    @Autowired
    private ICompomentInfoService compomentInfoService;

    /**
     * 查询构件维护列表
     */
    @PreAuthorize("@ss.hasPermi('project:info:list')")
    @GetMapping("/list")
    public TableDataInfo list(CompomentInfoListVO compomentInfoListVO)
    {
        startPage();
        List<CompomentInfoListVO> list = compomentInfoService.selectCompomentInfoList(compomentInfoListVO);
        return getDataTable(list);
    }

    /**
     * 导出构件维护列表
     */
    @PreAuthorize("@ss.hasPermi('project:info:export')")
    @Log(title = "构件维护", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CompomentInfoListVO compomentInfoListVO)
    {
        List<CompomentInfoListVO> list = compomentInfoService.selectCompomentInfoList(compomentInfoListVO);
        ExcelUtil<CompomentInfoListVO> util = new ExcelUtil<CompomentInfoListVO>(CompomentInfoListVO.class);
        util.exportExcel(response, list, "构件维护数据");
    }

    /**
     * 获取构件维护详细信息
     */
    @PreAuthorize("@ss.hasPermi('project:info:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(compomentInfoService.selectCompomentInfoById(id));
    }

    /**
     * 新增构件维护
     */
    @PreAuthorize("@ss.hasPermi('project:info:add')")
    @Log(title = "构件维护", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CompomentInfo compomentInfo)
    {
        return toAjax(compomentInfoService.insertCompomentInfo(compomentInfo));
    }

    /**
     * 修改构件维护
     */
    @PreAuthorize("@ss.hasPermi('project:info:edit')")
    @Log(title = "构件维护", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CompomentInfo compomentInfo)
    {
        return toAjax(compomentInfoService.updateCompomentInfo(compomentInfo));
    }

    /**
     * 删除构件维护
     */
    @PreAuthorize("@ss.hasPermi('project:info:remove')")
    @Log(title = "构件维护", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(compomentInfoService.deleteCompomentInfoByIds(ids));
    }

    /**
     * 查询构件详情列表接口
     */
    @PreAuthorize("@ss.hasPermi('project:info:modellist')")
    @GetMapping("/modellist")
    public TableDataInfo list(CompomentInfoVO compomentInfoVO)
    {
        startPage();
        List<CompomentInfoVO> list = compomentInfoService.selectCompomentInfoVOList(compomentInfoVO);
        return getDataTable(list);
    }
}
